package com.tanhua.app.controller;

import com.tanhua.app.service.TanhuaService;
import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaContorller {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 今日佳人
     * GET/tanhua/todayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> todayBest() {

        // 执行方法
        TodayBest todayBest = tanhuaService.todayBest();

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 推荐朋友
     * GET/tanhua/recommendation
     */
    @GetMapping("/recommendation")
    public ResponseEntity<PageResult<TodayBest>> recommendation(RecommendUserDto recommendUserDto) {

        // 执行方法
        PageResult<TodayBest> pageResult = tanhuaService.recommendation(recommendUserDto);

        return ResponseEntity.ok(pageResult);
    }


    /**
     * 佳人信息
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity<TodayBest> findRecommendByUserId(@PathVariable Long id) {
        TodayBest todayBest = tanhuaService.findRecommendByUserId(id);

        return ResponseEntity.ok(todayBest);
    }


    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity<String> strangerQuestions(Long userId) {
        String txt =  tanhuaService.findQuestion(userId);

        return ResponseEntity.ok(txt);
    }

    /**
     * 回复陌生人问题
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity send(@RequestBody Map<String, Object> map) {
        // 解析参数
        Long userId = Long.parseLong(map.get("userId").toString()) ;
        String reply = map.get("reply").toString();

        tanhuaService.sendQuestions(userId, reply);

        return ResponseEntity.ok(null);
    }


    /**
     * 探花列表
     */
    @GetMapping("/cards")
    public ResponseEntity<List<TodayBest>> findCards() {
        List<TodayBest> list = tanhuaService.findCards();

        return ResponseEntity.ok(list);
    }

    /**
     * 探花喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity saveLove(@PathVariable("id")Long likeUserId) {
        tanhuaService.saveUserLikeByLove(likeUserId);

        return ResponseEntity.ok(null);
    }

    /**
     * 探花不喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity saveUnLove(@PathVariable("id")Long likeUserId) {
        tanhuaService.saveUserLikeByUnLove(likeUserId);

        return ResponseEntity.ok(null);
    }


    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,@RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = tanhuaService.search(gender, distance);

        return ResponseEntity.ok(list);
    }

}
